package com.yc.io;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 使用http测试ping命令
 *
 * @author samuelchen
 * @version 1.0
 * @date 2022-02-16
 */
public class NetPingDemo {

    public static void main(String[] args) {
        try {
            String url = "https://www.baidu.com";
            URL siteUrl = new URL(url);
            HttpURLConnection httpURLConnection = (HttpURLConnection) siteUrl.openConnection();
            httpURLConnection.setRequestMethod("GET");
            httpURLConnection.setConnectTimeout(3000);
            httpURLConnection.connect();
            int responseCode = httpURLConnection.getResponseCode();
            System.out.println(responseCode);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
